﻿using PTop.Code;
using PTop.Domain.Entity.WeChat;
using PTop.Domain.IRepository.WeChat;
using PTop.Repository.WeChat;
using System.Collections.Generic;

namespace PTop.Application.WeChat
{
    /// <summary>
    /// 微信AccessTokenApp
    /// </summary>	
    public class WxAccessTokenApp
    {
        private IWxAccessTokenRepository service = new WxAccessTokenRepository();

        public List<WxAccessTokenEntity> GetList(Pagination pagination, string keyword)
        {
            var expression = ExtLinq.True<WxAccessTokenEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                //expression = expression.And(t => t.F_OrgnaizeName.Contains(keyword));
                //expression = expression.Or(t => t.F_CreatorUserCode.Contains(keyword));
            }
            return service.FindList(expression, pagination);
        }

        public WxAccessTokenEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }

        public WxAccessTokenEntity GetForm()
        {
            return service.FindEntity(m => true);
        }

        public void Delete(string keyValue)
        {
            service.Delete(t => t.F_Id == keyValue);
        }

        public void SubmitForm(WxAccessTokenEntity entity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                service.Update(entity);
            }
            else
            {
                service.Insert(entity);
                service.Delete(m => m.F_Id != entity.F_Id);
            }
        }

    }
}